<template>
<div>
  <el-button size="medium" type="primary" plain @click="goBack" >返回</el-button>
  <div style="padding-top: 30px;padding-inline-start: 30px;">
<!--  执业人员财务统计清单  -->
<div style="text-align: center;font-size: 25px"><b>心心念念律师事务所执业人员财务清单</b></div>
<div style="height: 20px"></div>
<span style="font-size: 14px;font-weight:bold">执业人员：<span>{{MyCwStatistics.empName}}</span>&nbsp;&nbsp;日期：<span>{{MyCwStatistics.dateStart}}&nbsp;&nbsp;至&nbsp;&nbsp;{{MyCwStatistics.dateEnd}}</span></span>
    <div style="height: 20px"></div>
    <span style="font-size: 14px;font-weight:bold">律师日期内创收</span>

    <!--        height="300px"-->
    <el-table

        :data="changshou"
        show-summary
        :summary-method="JineSum"
        style="width: 100%">
      <el-table-column
          prop="case_attorney"
          label="承办律师">
      </el-table-column>
      <el-table-column
          prop="case_no"
          label="案号">
      </el-table-column>
      <el-table-column
          prop="case_wtr"
          label="委托人">
      </el-table-column>
      <el-table-column
          prop="case_opposite_parties"
          label="对方当事人">
      </el-table-column>
      <el-table-column
          prop="collection_time"
          label="收款日期">
      </el-table-column>
      <el-table-column
          prop="casejine"
          label="收款金额">
      </el-table-column>
      <el-table-column
          prop="case_remarks"
          label="备注">
      </el-table-column>
      <template slot="empty">
      <div style="height: 10%">
        <span>没有找到匹配数据</span>
      </div>
      </template>
    </el-table>

    <div style="height: 30px"></div>

    <span style="font-size: 14px;font-weight:bold">律师日期内创收提成</span>

<!--     height="300px"-->
    <el-table

        :data="changshouTc"
        show-summary
        :summary-method="JineSum"
        style="width: 100%">
      <el-table-column
          prop="case_attorney"
          label="承办律师">
      </el-table-column>
      <el-table-column
          prop="case_no"
          label="案号">
      </el-table-column>
      <el-table-column
          prop="case_wtr"
          label="委托人">
      </el-table-column>
      <el-table-column
          prop="case_opposite_parties"
          label="对方当事人">
      </el-table-column>
      <el-table-column
          prop="casejine"
          label="创收金额">
      </el-table-column>
      <el-table-column
          prop="ticheng"
          label="实际提成">
      </el-table-column>
      <template slot="empty">
        <div  style="height: 10%">
          <span>没有找到匹配数据</span>
        </div>
      </template>
    </el-table>

    <div style="height: 30px"></div>

    <span style="font-size: 14px;font-weight:bold">本月实际收入</span>

<p>基本工资 (+):<span>{{CwEmpincome.cw_basic_salary || 0}}</span>元</p>
    <p>案件提成 (+):<span>{{empTicheng || 0}}</span>元</p>
    <p>其他收入 (+):<span>{{ (CwEmpincome.cw_level_salary || 0) + (CwEmpincome.cw_overtime_wage || 0) }}</span>元</p>
    <p>其他支出 (-):<span>{{ (CwEmpincome.cw_management_cost || 0) + (CwEmpincome.cw_accumulation_fund || 0) + (CwEmpincome.cw_pension_insurance || 0) + (CwEmpincome.cw_other_fixed_expenses || 0) +  (CwEmpincome.cw_individual_income_tax || 0) + (CwEmpincome.cw_attendance_deduction || 0)  }}</span>元</p>

<p style="font-size: 18px;font-weight:bold">合计本月应提:<span>{{ (CwEmpincome.cw_basic_salary || 0) + (empTicheng || 0) + (CwEmpincome.cw_level_salary || 0) + (CwEmpincome.cw_overtime_wage || 0) - ((CwEmpincome.cw_management_cost || 0) + (CwEmpincome.cw_accumulation_fund || 0) + (CwEmpincome.cw_pension_insurance || 0) + (CwEmpincome.cw_other_fixed_expenses || 0) +  (CwEmpincome.cw_individual_income_tax || 0) + (CwEmpincome.cw_attendance_deduction || 0) ) || 0 }}</span>元</p>

  </div>
</div>
</template>

<script>
export default {
  name: "queryPractitionersCwStatistics",
  data(){
    return{
      MyCwStatistics:this.$route.params,
      changshou:[], // 创收表数据存放
      changshouTc:[], // 创收提成
      CwEmpincome:{}, // 员工工资
      empTicheng:0, //案件提成
    }
  },
  created() {
    this.queryCwEmpincome();
this.queryCreateIncome();
    this.queryCommission();

  },
  methods:{
    goBack(){this.$router.go(-1)},
    // 创收查询
    queryCreateIncome(){
      const loading = this.$loading({
        lock: true,
        text: '正在载入...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      this.$http.get('statistics/CreateIncome',{params:this.MyCwStatistics})
      .then(res => {
        setTimeout(() => {
          loading.close();
        });
        this.changshou = res.data.data
      })
      .catch()
    },
    JineSum( param){ // 创收总金额计算
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === 'casejine' || column.property === 'ticheng') {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index]+= ' 元';

        }
      });

      return sums
    },

    // 创收提成查询
    queryCommission(){
      const loading = this.$loading({
        lock: true,
        text: '正在载入...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      this.$http.get("statistics/Commission",{params:this.MyCwStatistics})
      .then(res => {

        setTimeout(() => {
          loading.close();
        });
        this.changshouTc = res.data.data
        for(var i=0;i<this.changshouTc.length;i++){
          this.empTicheng += this.changshouTc[i].ticheng == null || ''?0:this.changshouTc[i].ticheng
        }
      })
      .catch()
    },
    // 基本工资查询
  queryCwEmpincome(){
    const loading = this.$loading({
      lock: true,
      text: '正在载入...',
      spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.7)'
    });
    this.$http.get("statistics/empGongZi",{params:this.MyCwStatistics})
    .then(res => {

      setTimeout(() => {
        loading.close();
      });
      this.CwEmpincome = res.data.data
    })
    .catch()
  },


  }
}
</script>

<style scoped>

</style>